package cn.good.yan.controller;

import cn.good.yan.pojo.Bill;
import cn.good.yan.pojo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;


/**
 * 演示：
 *      客户端 请求 服务端接口
 *      演示： Sentinel 整合openFeign + fallback
 *
 * @author shengren.yan
 * @create 2024-01-09
 */
@RestController
@RequestMapping("/t2")
@Slf4j
public class Test2Controller {

    @Value("${server.port}")
    private String serverPort;

    public static HashMap<Long, Bill> hashMap = new HashMap<>();

    static {
        hashMap.put(1L, new Bill(1L, "12才子"));
        hashMap.put(2L, new Bill(2L, "b团"));
        hashMap.put(3L, new Bill(3L, "6余字"));
    }

    // 模拟 - 从数据库查出数据，返回给客户端
    @GetMapping(value = "/one/{id}")
    public CommonResult<Bill> one1(@PathVariable("id") Long id) {
        Bill bill = hashMap.get(id);
        CommonResult<Bill> result = new CommonResult(200, "端口:  " + serverPort, bill);
        return result;
    }


}
